package no.ntnu.idi.evaluering;

public class EvaluationScore {
		
	private int truePostives = 0;
	private int trueNegatives = 0;
	private int falsePositives = 0;
	private int falseNegatives = 0;
	
	private String mName;
	private String mGoldStandardName;
	
	public EvaluationScore(EvaluationList goldStandardList, EvaluationList comparisonList) {
		if(goldStandardList.size() != comparisonList.size()) {
			throw new IllegalArgumentException("inputmaps need to be equal");
		}
		mGoldStandardName =  goldStandardList.getName();
		mName = comparisonList.getName();
		setStats(goldStandardList, comparisonList);		
	}
	
	private void setStats(EvaluationList goldStandardList, EvaluationList comparisonList) {
		for(int i = 0; i < goldStandardList.size(); i++) {
			if(!goldStandardList.get(i).getKey().equals(comparisonList.get(i).getKey())) {
				throw new IllegalArgumentException("Listene kan ikke sammenliges siden de ikke er like");
			}
			boolean goldStandardValue = goldStandardList.get(i).isSensitiv();
			boolean mapValue = comparisonList.get(i).isSensitiv();		
			if(mapValue) {
				if (goldStandardValue) {
					truePostives++;
				} else {
					falsePositives++;
				}
			}
			else {
				if (!goldStandardValue) {
					trueNegatives++;
				} else {
					falseNegatives++;
				}
			}
		}
	}
		
	
	public double calculateRecall() {
		return (double)truePostives/((double)truePostives+(double)falseNegatives);
	}
	
	public double calculatePrecision() {
		return ((double)truePostives/((double)truePostives+(double)falsePositives));
	}
	
	public double calculateFallout() {
		return ((double)falsePositives/((double)trueNegatives+(double)falsePositives));
	}
	
	public double calculateFMeasure(double beta) {
		double recall = calculateRecall();
		double precision = calculatePrecision();
		return ((1.0+beta*beta)*recall*precision)/(recall+(beta*beta*precision));
	}
	
	public String getName() {
		return mName;
	}

	public String getGoldStandardName() {
		return mGoldStandardName;
	}

}
